﻿@using KPIS.GERP.Models.ICM
@model IEnumerable<KPIS.GERP.Models.ICM.Warehouse>

@{
    ViewBag.Title = "ข้อมูลพื้นฐาน";
    ViewBag.Descr = "คลังพัสดุ";
}

@using (Html.BeginForm("DeleteAll", "Warehouse", FormMethod.Post, new { id="form" }))
{
    @Html.AntiForgeryToken()
    <div class="row-fluid">
        <div class="block-button-menu-above">
            @Html.ButtonAdd()
            @Html.ButtonDeleteAll()
        </div>

          @Html.ValidationSummary(true, "", new { @class = "alert alert-error" })
        
        <div class="row-fluid">
            <div class="table-header span12">
                <div class="span10">
                   รายละเอียดคลังพัสดุ
                </div>
                @Html.Partial("_ExportButton")
            </div>
        </div>

        <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
            <thead>
                <tr>
                    <th class="center" style="width:50px;">
                        <label>
                            <input type="checkbox"/>
                            <span class="lbl"></span>
                        </label>
                    </th>
                    <th>
                        ประเภท
                    </th>
                    <th>
                        ชื่อ
                    </th>
                    <th>
                        หน่วยงานที่รับผิดชอบ
                    </th>
                    <th>
                        รายละเอียด
                    </th>
                    <th>&nbsp;</th>
                </tr>
            </thead>

            <tbody>
                @foreach (var m in Model)
                {
                  <tr>
                    <td class="center">
                            <label>
                                <input type="checkbox" name="deleteIds" value="@(m.WhId)" />
                                <span class="lbl"></span>
                            </label>
                    </td>
                  
                      <td>@Html.DisplayFor(modelItem => m.Scope.LookUpName)</td>
                      <td>@Html.ActionLink(m.Name, "Details", new RouteValueDictionary{{"id",m.WhId}})</td>
                      <td>@Html.DisplayFor(modelItem => m.JobSite.Name)</td>
                      <td>@Html.DisplayFor(modelItem => m.Description)</td>
                
                        <td class="td-actions">
                            <div class="hidden-phone visible-desktop btn-group">
                                @Html.ButtonDetails(new { Id = m.WhId }, true)
                                
                                @Html.ButtonEdit(new { Id = m.WhId }, true)

                                @Html.ButtonDelete(new { Id = m.WhId }, true)
                            </div>

                            <div class="hidden-desktop visible-phone">
                                <div class="inline position-relative">
                                    <button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown">
                                        <i class="icon-caret-down icon-only bigger-120"></i>
                                    </button>

                                    <ul class="dropdown-menu dropdown-icon-only dropdown-yellow pull-right dropdown-caret dropdown-close">
                                        <li>
                                            <a href="@Url.Action("Details", "Warehouse")/@(m.WhId)" class="tooltip-gray" data-rel="tooltip" title="ดูรายละเอียด" data-placement="left">
                                                <span class="gray">
                                                    <i class="icon-search"></i>
                                                </span>
                                            </a>
                                        </li>

                                        <li>
                                            <a href="@Url.Action("Edit", "Warehouse")/@(m.WhId)" class="tooltip-success" data-rel="tooltip" title="แก้ไข" data-placement="left">
                                                <span class="green">
                                                    <i class="icon-edit"></i>
                                                </span>
                                            </a>
                                        </li>

                                        <li>
                                            <a href="@Url.Action("Delete", "Warehouse")/@(m.WhId)" class="tooltip-error" data-rel="tooltip" title="ลบ" data-placement="left">
                                                <span class="red">
                                                    <i class="icon-trash"></i>
                                                </span>
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </td>
                    </tr>
                }
           
            </tbody>
        </table>
    </div>
}

@section scripts
{
    
	<script type="text/javascript">
	    $(function () {
	        var oTable1 = $('#table').dataTable({
	            "aoColumns": [
                    { "bSortable": false },
                    null,
                    null,
	                null,
                    null,
                    { "bSortable": false }
	            ]
	        });

	        $('table th input:checkbox').on('click', function () {
	            var that = this;
	            $(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function () {
				    this.checked = that.checked;
				    $(this).closest('tr').toggleClass('selected');
				});

	        });

	        $('[data-rel=tooltip]').tooltip();

	        $("form").submit(function () {
	            var currentForm = this;
	            bootbox.confirm(function(result) {
	                var _result = result;
	                if (result) {
	                    $.ajax({
	                        url: '@Url.Action("DeleteAll")', //"DeleteAll",
	                        type: "post",
	                        dataType: "json",
	                        data: $(currentForm).serialize(),
	                        success: function(result) {
	                            if (result.success) {
	                                location.reload();
	                            } else {
	                            }
	                        }
	                    });
	                }
	            })
	            return false;
	        });
	    })

	</script>
}